# GET Command Generator
from pysnmp.entity.rfc3413.oneliner import cmdgen
from pysnmp.proto.rfc1902 import ObjectName

moid='1.3.6.1.2.1.2.2.1'
soid='.6.6'
oid = ObjectName( moid+soid )
ip='192.168.20.35'
errorIndication, errorStatus, \
                 errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
    # SNMP v1
#    cmdgen.CommunityData('test-agent', 'public', 0),
    # SNMP v2
    cmdgen.CommunityData(ip, 'public'),
    # SNMP v3
#    cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
    cmdgen.UdpTransportTarget((ip, 161)),
    # Plain OID 
    #1.3.6.1.2.1.2.2.1.6.2
    #1,3,6,1,2,1,1,3,0 TimeTicks
    # 1,3,6,1,2,1,2,2,1,6,2 OctetString
    # 1,3,6,1,4,1,5959,1,1,4,1,1,2,1 OctetString
    # 1,3,6,1,2,1,4,22,1,2,2,172,17,119,254
    # 1,3,6,1,4,1,5959,1,1,1,1,1,9,1
    # 1,3,6,1,2,1,2,2,1,6,6
    oid,
    # ((mib-name, mib-symbol), instance-id)
    # (('SNMPv2-MIB', 'sysObjectID'), 0)
    )

if errorIndication:
    print errorIndication
else:
    if errorStatus:
        print '%s at %s\n' % (
            errorStatus.prettyPrint(),
            errorIndex and varBinds[int(errorIndex)-1] or '?'
            )
    else:
        for name, val in varBinds:
            print name,val,type(val),'-'.join(['%x' % ord(x) for x in val]),'-'.join(['%x' % ord(x) for x in val.prettyPrint()])
            print '%s = %s' % (name.prettyPrint(), val.prettyPrint())